function [stim stim_order] = stim_list(phase,taskname,varargin)
stim_order={};
switch phase
    case 'training1'
        n_trials = 3;
        %n_trials = 8;
        difficulty=1;

    case 'staircase'
        
        n_trials = 60;
        difficulty=0.5;

    case 'training2'
        
        n_trials = 3;
        staircase  = varargin{1};
         difficulty = staircase.trial(end).stim.x;
%         difficulty =0.5;
    case 'task'
        
        n_trials_per_block = 30;
        blocks = varargin{1};
        n_blocks = length(blocks);
        n_trials = n_blocks*n_trials_per_block;
        staircase  = varargin{2};
        r=[];
        for i=0:9
            r=[r,staircase.trial(end-i).stim.x];
        end
        difficulty = mean(r);
%        difficulty =0.5;
    otherwise
        error
end



stim=repmat(struct('difficulty',difficulty),1,n_trials);

switch taskname
    case 'baldassi'
        for i=1:n_trials
            stim(i).difficulty = difficulty;
            stim(i).corr = sign(rand-.5);
            stim(i).angle = 45*difficulty*stim(i).corr;
            stim(i).n = 6;
        end

    case 'sternbergfaces'
        folder = '../stimuli/fractales/';
        filenames=dir([folder '*.*']);       
        filenames={filenames(~[filenames.isdir]).name};
        filenames=strcat(folder,filenames(:));
        n_load = 4;
        [files,trialtype] = sternberg_files(filenames,n_trials,n_load);
        for i=1:n_trials
            stim(i).images = files(:,i);
            stim(i).delay=0.7;
            stim(i).corr = trialtype(i);
        end

    case 'emotion'
%         folder_happy = '../../../Pictures/'
%         filenames_happy=dir([folder_happy '*.jpg']);
        folder_happy='../stimuli/faces_happy/';        
        filenames_happy=dir([folder_happy '*.*']);
        filenames_happy={filenames_happy(~[filenames_happy.isdir]).name};
        filenames_happy=strcat(folder_happy,filenames_happy(:));
        
        folder_neutral='../stimuli/faces_neutral/';
        filenames_neutral=dir([folder_neutral '*.*']);
        filenames_neutral={filenames_neutral(~[filenames_neutral.isdir]).name};
        filenames_neutral=strcat(folder_neutral,filenames_neutral(:));
        
        [files,trialtype] = emotion_files(filenames_happy,filenames_neutral,n_trials);
        
        for i=1:n_trials
            stim(i).noise=difficulty;
            stim(i).image = files(i);
            stim(i).corr = trialtype(i); %0=neutre, 1=happy
            
        end
end

switch phase
    case 'task'
        stim_order = cell(1,n_blocks);
        for i=1:n_blocks
            stim_order{i} = [1:n_trials_per_block]+(i-1)*n_trials_per_block;
        end
end

return

